package cc.mrbird.trans.transquery;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.domain.ResponseBo;
import cc.mrbird.common.util.FileUtils;
import cc.mrbird.job.domain.JobLog;
import cc.mrbird.job.domain.Trans;
import cc.mrbird.job.service.JobLogService;
import cc.mrbird.system.service.TransService;

@Controller
public class TransQueryController extends BaseController {
	@Autowired
	private TransService transService;

	@Log("获取调度日志信息")
	@RequestMapping("trans")
	@RequiresPermissions("trans:query")
	public String index() {
		return "trans/query/transDetailQuery";
	}

	@RequestMapping("trans/list")
	@ResponseBody
	public Map<String, Object> jobLogList(QueryRequest request, JobLog log) {
		PageHelper.startPage(request.getPageNum(), request.getPageSize());
		Trans trans = new Trans();
		List<Trans> list = this.transService.findTransWithSel(trans);
		PageInfo<Trans> pageInfo = new PageInfo<>(list);
		return getDataTable(pageInfo);
	}

	
	@RequestMapping("trans/excel")
	@ResponseBody
	public ResponseBo transExcel(Trans trans) {
		try {
			List<Trans> list = this.transService.findTransWithSel(trans);
			return FileUtils.createExcelByPOIKit("交易明细表", list, Trans.class);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseBo.error("导出Excel失败，请联系网站管理员！");
		}
	}

	@RequestMapping("trans/csv")
	@ResponseBody
	public ResponseBo transCsv(Trans trans) {
		try {
			List<Trans> list = this.transService.findTransWithSel(trans);
			return FileUtils.createCsv("交易明细表", list, Trans.class);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseBo.error("导出Csv失败，请联系网站管理员！");
		}
	}
	
}
